package com.example.wan_android.adapter


import android.view.ViewGroup
import android.widget.TextView
import com.example.wan_android.BR
import com.example.wan_android.R
import com.example.wan_android.core.CoreViewHolder
import com.example.wan_android.databinding.AdapterProjectTabBinding
import com.example.wan_android.http.bean.ProjectCategoryItemData
import com.example.wan_android.viewmodel.ProjectViewModel

class ProjectTabAdapter(vm: ProjectViewModel) :
    CoreAdapter<AdapterProjectTabBinding, ProjectViewModel, ProjectCategoryItemData>(
        BR.data,
        BR.viewModel,
        vm
    ) {
    override fun getItemLayoutId(viewType: Int): Int {
        return R.layout.adapter_project_tab
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CoreViewHolder {
        val holder = super.onCreateViewHolder(parent, viewType)
        holder.binding.root.findViewById<TextView>(R.id.tv_project_tab)
            .setOnClickListener {
                val position = holder.adapterPosition
                mViewModel?.setPosition(position)
                notifyDataSetChanged()
                mViewModel?.showProjectCategoryContent(mListData[position].id)
            }
        return holder
    }

    override fun onBindViewHolder(holder: CoreViewHolder, position: Int) {
        super.onBindViewHolder(holder, position)
        holder.binding.root.findViewById<TextView>(R.id.tv_project_tab).isSelected =
            mViewModel?.position?.value == position
    }
}